package com.bdq.interaction.api.client;

import cn.hutool.core.convert.Convert;
import com.bdq.common.entity.common.CommonResult;
import com.bdq.common.entity.common.PageResult;
import com.bdq.common.feign.interaction.InteractionFeign;
import com.bdq.common.feign.interaction.param.InteractionDataGetParam;
import com.bdq.common.feign.interaction.param.InteractionNumInitParam;
import com.bdq.common.feign.interaction.param.UserInteractionPageParam;
import com.bdq.common.feign.interaction.param.VoteInitParam;
import com.bdq.common.feign.interaction.vo.InteractionDataGetVO;
import com.bdq.common.feign.interaction.vo.InteractionDataListVO;
import com.bdq.interaction.application.model.cmd.InteractionNumInitCmd;
import com.bdq.interaction.application.model.cmd.VoteInitCmd;
import com.bdq.interaction.application.model.dto.InteractionDataGetAppDTO;
import com.bdq.interaction.application.model.dto.InteractionDataListAppDTO;
import com.bdq.interaction.application.model.query.InteractionDataGetQry;
import com.bdq.interaction.application.model.query.UserInteractionPageQry;
import com.bdq.interaction.application.service.InteractionAppCmdService;
import com.bdq.interaction.application.service.InteractionAppQueryService;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author malei
 * @date 2024-05-15 18:01
 */
@RestController
public class InteractionFeignImpl implements InteractionFeign {

    @Resource
    private InteractionAppCmdService interactionAppCmdService;

    @Resource
    private InteractionAppQueryService interactionAppQueryService;

    @Override
    public CommonResult<Boolean> interactionNumInit(InteractionNumInitParam param) {
        interactionAppCmdService.interactionNumInit(Convert.convert(InteractionNumInitCmd.class, param));
        return CommonResult.success(true);
    }

    @Override
    public CommonResult<Boolean> voteInit(VoteInitParam param) {
        interactionAppCmdService.voteInit(Convert.convert(VoteInitCmd.class, param));
        return CommonResult.success(true);
    }

    @Override
    public CommonResult<InteractionDataGetVO> getData(InteractionDataGetParam param) {
        InteractionDataGetAppDTO interactionDataGetAppDTO = interactionAppQueryService.getData(Convert.convert(InteractionDataGetQry.class, param));
        return CommonResult.success(Convert.convert(InteractionDataGetVO.class, interactionDataGetAppDTO));
    }

    @Override
    public CommonResult<List<InteractionDataListVO>> listData(Long userId, List<Long> contentIds) {
        List<InteractionDataListAppDTO> interactionDataListAppDTOList = interactionAppQueryService.listData(userId, contentIds);
        return CommonResult.success(Convert.toList(InteractionDataListVO.class, interactionDataListAppDTOList));
    }

    @Override
    public CommonResult<PageResult<Long>> pageUserInteraction(UserInteractionPageParam param) {
        PageResult<Long> pageResult = interactionAppQueryService.pageUserInteraction(Convert.convert(UserInteractionPageQry.class, param));
        return CommonResult.success(pageResult);
    }
}
